﻿Imports System.Runtime.InteropServices

Public Class VerticalProgressBar

    Inherits ProgressBar

    Public Const GWL_STYLE As Integer = &HFFFFFFF0

    Public Const PBS_VERTICAL As Integer = &H4

    Public Shared Function GetWindowLong(ByVal hWnd As HandleRef, ByVal nIndex As Integer) As IntPtr
        If (IntPtr.Size = 4) Then
            Return VerticalProgressBar.GetWindowLong32(hWnd, nIndex)
        End If
        Return VerticalProgressBar.GetWindowLongPtr64(hWnd, nIndex)
    End Function 'GetWindowLong

    <DllImport("user32.dll", EntryPoint:="GetWindowLong", CharSet:=CharSet.Auto)> _
    Private Shared Function GetWindowLong32(ByVal hWnd As HandleRef, ByVal nIndex As Integer) As IntPtr

    End Function 'GetWindowLong32

    <DllImport("user32.dll", EntryPoint:="GetWindowLongPtr", CharSet:=CharSet.Auto)> _
    Private Shared Function GetWindowLongPtr64(ByVal hWnd As HandleRef, ByVal nIndex As Integer) As IntPtr

    End Function 'GetWindowLongPtr64

    Public Shared Function SetWindowLong(ByVal hWnd As HandleRef, ByVal nIndex As Integer, ByVal dwNewLong As HandleRef) As IntPtr
        If (IntPtr.Size = 4) Then

            Return VerticalProgressBar.SetWindowLongPtr32(hWnd, nIndex, dwNewLong)

        End If

        Return VerticalProgressBar.SetWindowLongPtr64(hWnd, nIndex, dwNewLong)

    End Function 'SetWindowLong

    <DllImport("user32.dll", EntryPoint:="SetWindowLong", CharSet:=CharSet.Auto)> _
    Private Shared Function SetWindowLongPtr32(ByVal hWnd As HandleRef, ByVal nIndex As Integer, ByVal dwNewLong As HandleRef) As IntPtr

    End Function 'SetWindowLongPtr32

    <DllImport("user32.dll", EntryPoint:="SetWindowLongPtr", CharSet:=CharSet.Auto)> _
    Private Shared Function SetWindowLongPtr64(ByVal hWnd As HandleRef, ByVal nIndex As Integer, ByVal dwNewLong As HandleRef) As IntPtr

    End Function 'SetWindowLongPtr64

    Private Sub MyProgressBar_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleCreated

        Dim style As Integer = CInt(VerticalProgressBar.GetWindowLong(New HandleRef(Me, MyBase.Handle), GWL_STYLE))
        style = (style Or PBS_VERTICAL)
        VerticalProgressBar.SetWindowLong(New HandleRef(Me, MyBase.Handle), GWL_STYLE, New HandleRef(Me, CType(style, IntPtr)))
    End Sub
End Class 'MyProgressBar